package com.bjpowernode.shop.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjpowernode.shop.base.BaseStore;
import com.bjpowernode.shop.constants.CommonConstants;
import com.bjpowernode.shop.domain.PickAddr;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shop/pickAddr")
public class PickAddrController extends BaseStore {

    @GetMapping("/page")
    public ResponseEntity<Page<PickAddr>> page(Page<PickAddr> page, String addrName) {
        return ResponseEntity.ok(
                pickAddrService.page(
                        page,
                        new LambdaQueryWrapper<PickAddr>().like(
                                StringUtils.isNotBlank(addrName), PickAddr::getAddrName, addrName
                        )
                ));
    }
    
    @PostMapping
    @Transactional
    public ResponseEntity<Boolean> save(@RequestBody PickAddr pickAddr) {
        pickAddr.setShopId(CommonConstants.DEFAULT_SHOP_ID);
        boolean flag = pickAddrService.save(pickAddr);
        return ResponseEntity.ok(flag);
    }
}
